using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Administration_Toolkit_v2;

namespace LocalizationAdminTool
{
    public partial class ExportMasterDiffResxFile : Form
    {
        public ExportMasterDiffResxFile()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Export Differents in a Master Resx Format
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExport_Click_1(object sender, EventArgs e)
        {
            try
            {
                string strCultureName;
                string strApplicationName;
                string strDirectoryName;
                string strFileName;
                DateTime lastUpdatedDate;
                lastUpdatedDate = Convert.ToDateTime(LastUpdatedDateTimePicker.Value);
                
                if (cmbCultures.Text.Trim() == "All")
                {
                    foreach (DataRowView tmpCulture in cmbCultures.Items)
                    {
                        if (tmpCulture[1].ToString().Trim() != "All")
                        {
                            strCultureName = tmpCulture[1].ToString();
                            strApplicationName = cmbApplications.Text;
                            strDirectoryName = txtDirectory.Text.Trim();
                            if (!(strDirectoryName[strDirectoryName.Length - 1].Equals(@"\")))
                            {
                                strDirectoryName += @"\";
                            }
                            if (strCultureName == "inv")
                            {
                                strFileName = strDirectoryName + strApplicationName.Replace(" ", " ") + ".resx";
                            }
                            else
                            {
                                strFileName = strDirectoryName + strApplicationName.Replace(" ", " ") + "." + strCultureName + ".Diff.resx";
                            }

                            Utilities.ExportMasterDiffResxFile(strApplicationName, strCultureName, strFileName,lastUpdatedDate,strFileName);
                        }
                    }

                }
                else
                {
                    strCultureName = cmbCultures.Text;
                    strApplicationName = cmbApplications.Text;
                    strDirectoryName = txtDirectory.Text.Trim();
                    if (!(strDirectoryName[strDirectoryName.Length - 1].Equals(@"\")))
                    {
                        strDirectoryName += @"\";
                    }
                    if (strCultureName == "inv")
                    {
                        strFileName = strDirectoryName + strApplicationName.Replace(" ", " ") + ".resx";
                    }
                    else
                    {
                        strFileName = strDirectoryName + strApplicationName.Replace(" ", " ") + "." + strCultureName + ".Diff.resx";
                    }

                    Utilities.ExportMasterDiffResxFile(strApplicationName, strCultureName, strFileName,lastUpdatedDate,strFileName);
                }
                txtStatus.Text = "Files Exported";
            }
            catch (Exception ex)
            {
                txtStatus.Text = ex.Message;
            }
        }     

        private void btnClose_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmbApplications_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            string strApplicationName = cmbApplications.Text;
            cmbCultures.DataSource = Utilities.GetApplicationCultureList(cmbApplications.Text);
            cmbCultures.ValueMember = "CultureID";
            cmbCultures.DisplayMember = "CultureName";
        }

        private void ExportMasterDiffResxFile_Load_1(object sender, EventArgs e)
        {
            cmbApplications.DataSource = Utilities.GetApplicationList();
            cmbApplications.ValueMember = "ApplicationID";
            cmbApplications.DisplayMember = "ApplicationName";
            cmbCultures.DataSource = Utilities.GetApplicationCultureList(cmbApplications.Text);
            cmbCultures.ValueMember = "CultureID";
            cmbCultures.DisplayMember = "CultureName";

        }

        private void btnSelectDirectory_Click_1(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            txtDirectory.Text = folderBrowserDialog1.SelectedPath;
        }       
      
    }
}

